package action;

//import java.io.BufferedReader;
//import java.io.IOException;
//import java.io.InputStreamReader;
import java.sql.SQLException;
//import java.util.ArrayList;
//import java.util.HashMap;
import java.util.List;
import java.util.Map;
//import java.util.Scanner;

import dao.StudentsDao;
import model.Students;

/**
 * MVC三层模型
 * 控制层
 * @author jinmingwu
 *
 */
public class StudentsAction {

//	private static Scanner scanner;
//	private static BufferedReader keyin = new BufferedReader(new InputStreamReader(System.in));
//	//0.输入ID
//	public static int getId() throws IOException {
//		System.out.print("\n请输入需要查询的学生ID：");
//		return keyin.read();
//	}

	//1.查询所有学生信息
	public List<Students> query() throws Exception {
		StudentsDao dao = new StudentsDao();
		return dao.query();
	}

	//2.查找学生信息
	public List<Students> query(List<Map<String, Object>> params) throws Exception{
		StudentsDao dao = new StudentsDao();
		return dao.query(params);
	}
	
	//3.查询单个学生信息
	public Students get(int p_id) throws SQLException {
		StudentsDao dao = new StudentsDao();
		return dao.get(p_id);
	}
	
	
	//4.更新学生信息
	public void update(Students student) throws SQLException{
		StudentsDao dao = new StudentsDao();
		dao.updateStudents(student);
	}
	
	//5.根据id删除学生信息
	public void delete(int p_id) throws SQLException {
		StudentsDao dao = new StudentsDao();
		dao.deleteStudents(p_id);
	}
	
	//6.新增学生信息
	public void add(Students student) throws Exception {
		StudentsDao dao = new StudentsDao();
		dao.addStudents(student);
//		Students student = new Students();
//		scanner = new Scanner(System.in);
//		//		student.setName("小婷");
//		//		student.setSex("女");
//		//		student.setTel("13192261111");
//		//		student.setBirthary("1995-11-11");
//		//		student.setAge(23);
//		String tmpString = null;
//		int tmpInt = 0;
//		System.out.print("请输入新增的学生姓名：");
//		tmpString = scanner.nextLine();
//		student.setName(tmpString);
//
//		System.out.print("请输入新增学生的性别：");
//		tmpString = scanner.nextLine();
//		student.setSex(tmpString);
//
//		System.out.print("请输入新增学生的出生日期：");
//		tmpString = scanner.nextLine();
//		student.setBirthday(tmpString);
//
//		System.out.print("请输入新增学生的联系电话：");
//		tmpString = scanner.nextLine();
//		student.setTel(tmpString);
//
//		System.out.print("请输入新增学生的年龄：");
//		tmpInt = scanner.nextInt();
//		student.setAge(tmpInt);
//
//		dao.addStudents(student);
	}


	public static void main(String[] args) throws Exception {
		// TODO Auto-generated method stub
		//add();
//		while(true) {
//			System.out.println("=====学生信息管理表======");
//			System.out.println("1.显示数据库中所有学生信息");
//			System.out.println("2.根据id查找学生信息");
//			System.out.println("3.根据id修改学生信息");
//			System.out.println("4.根据id删除学生信息");
//			System.out.println("5.新增学生信息");
//			System.out.println("0.退出");
//			System.out.print("请输入你的选择：");
//			BufferedReader keyin = new BufferedReader(new InputStreamReader(System.in));
//			String option = null;
//			option = keyin.readLine();
//			//String option = scanner.re();
//			switch(option) {
//			case "0":
//				System.out.println("已退出！");
//				System.exit(0);
//			case "1":
//				query();
//				System.out.println();
//				break;
//			case "2":
//				get(getId());
//				System.out.println();
//				break;
//			case "3":
//				update(getId());
//				System.out.println();
//				break;
//			case "4":
//				delete(getId());
//				System.out.println();
//				break;
//			case "5":
//				add();
//				System.out.println();
//				break;
//			default:
//				System.out.println("输入有误，请重新输入！");
//				break;
//			}
//		}

//		StudentsDao dao = new StudentsDao();
//		List<Map<String, Object>> params = new ArrayList<Map<String, Object>>();
//		Map<String, Object> param = new HashMap<String, Object>();
//		param.put("name", "name");
//		param.put("rela", "LIKE");
//		param.put("value", "'%小%'");
//		params.add(param);
//		param = new HashMap<String, Object>();
//		param.put("name", "tel");
//		param.put("rela", "LIKE");
//		param.put("value", "'%9226%'");
//		params.add(param);
//		
//		List<Students> list = dao.query(params);
//		for (Students students : list) {
//			System.out.println(students.toString());
//		}

//		student.setAge(32);
//		student.setTel("13112341234");
//		dao.updateStudents(student);
//		System.out.println(dao.get(1).toString());
	}

}
